/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package p1;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Set;

/**
 *
 * @author Derek Ward
 * 
 * A simple unit test for the DataFile object
 * 
 */
public class DataFileUnitTest 
{
    private     DataFile            df;
    private     String              fileName;
    HashMap<String, Node>         vhm;
    ArrayList<Edge>                 eal;
    
    public DataFileUnitTest(String s)
    {
        fileName = s;
    }
    
    public void execute()
    {
        try
        {
            df = new DataFile(fileName);
        }
        catch (NullPointerException ex)
        {
            System.err.println(ex.getMessage());
            System.err.println(ex.getStackTrace());
            System.exit(1);
        }
        
        try
        {
            df.readDataFile();
        }
        catch (IOException ex)
        {
            System.err.println(ex.getMessage());
            System.err.println(ex.getStackTrace());
            System.exit(1);
        }
        
        try
        {
            vhm = df.createNodeHashMap();
        }
        catch(IndexOutOfBoundsException ex)
        {
            System.err.println(ex.getMessage());
            System.err.println(ex.getStackTrace());
            System.exit(1);
        }
        
        try
        {
            eal = df.createEdgeArrayList(vhm);
        }
        catch ( IOException ex )
        {
            System.err.println(ex.getMessage());
            System.err.println(ex.getStackTrace());
            System.exit(1);
        }
        catch ( InvalidEdgeWeightException ex )
        {
            System.err.println(ex.getMessage());
            System.err.println(ex.getStackTrace());
            System.exit(1);
        }
        
        Set<String> s = vhm.keySet();
        Node v;
        
        for(String st : s)
        {
            v = vhm.get(st);
            System.out.println("Node: <" + v.getLabel() + ">");
            for(Edge e : v.m_connectedEdges)
            {
                System.out.println("\tEdge: [" + e.getSourceNode().getLabel() + 
                                    "]-(" + e.getWeight() + ")-[" + e.getDestinationNode().getLabel()
                                    + "]");
            }
        }
    }
}
